package com.ruoyi.samplemod.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.samplemod.domain.entity.Sample;
import com.ruoyi.samplemod.mapper.ACSampleMapper;
import com.ruoyi.samplemod.mapper.SampleMapper;
import com.ruoyi.samplemod.service.ACSampleService;
import com.ruoyi.samplemod.utils.ExcelListUtils;
import com.ruoyi.system.mapper.SysDeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ACSampleServiceImpl implements ACSampleService {
    @Autowired
    ACSampleMapper sampleMapper;

    @Autowired
    private SysDeptMapper deptMapper;


    @Override
    public ExcelListUtils selectSample(Integer pageSize,Integer pageNub) {
        PageHelper.startPage(pageNub,pageSize);
        List<Sample> sampleList = sampleMapper.selectSample();
        PageInfo<Sample> samplePageInfo=new PageInfo<>(sampleList);
        return new ExcelListUtils(samplePageInfo,sampleList);
    }

    @Override
    public ExcelListUtils selectSampleByDataByName(String queryTimeStar, String queryTimeEnd, String sampleCode, Integer pageSize, Integer pageNub) {
        PageHelper.startPage(pageNub,pageSize);
        List<Sample> sampleList = sampleMapper.selectSampleByDataByName(queryTimeStar,queryTimeEnd,sampleCode);
        PageInfo<Sample> samplePageInfo=new PageInfo<>(sampleList);
        return new ExcelListUtils(samplePageInfo,sampleList);
    }

    @Override
    public String addSample(Sample sample) {
        if(sampleMapper.sampleNameisExist(sample.getSampleCode())>0){
            return "该样本已存在";
        }
        sampleMapper.addSample(sample);
        return "添加成功";
    }

    @Override
    public Long delSample(Long id) {
        return sampleMapper.delSample(id);
    }

    @Override
    public List<Sample> selectSampleByDataByNameExcel(String timeStar, String timeEnd, String sampleCode) {
        return sampleMapper.selectSampleByDataByName(timeStar,timeEnd,sampleCode);
    }

    @Override
    public List<Sample> selectSampleAll() {
        return sampleMapper.selectSample();
    }

    @Override
    public List<Sample> selectSampleAllOrderByDept() {
        return sampleMapper.selectSampleAllOrderByDept();
    }


}
